package Models;

import java.sql.*;

import java.time.*;
import javafx.beans.property.*;

public class Device 
{
	
	//Declare DB objects 
	DBConnect conn = null;
	Statement stmt = null;
		
	//device class constructor function.
	public Device()
	{
		//create db object instance
		conn = new DBConnect();
	}
	
	// INSERT INTO METHOD
	public void insertUserToDb(String Name, String level) 
	{
	 	 try 
		 {
	  		stmt = conn.connect().createStatement();
	
	  		String sql = "INSERT INTO J_Wang_Device_user (level, name)" + " VALUES ('"+level +"', '"+Name+"' )";
	  		stmt.executeUpdate(sql);
	  		conn.connect().close();
		}
		catch (SQLException se)
		{ se.printStackTrace();  }
	}// INSERT INTO METHOD

	//SELECT METHOD
	public void insertSisgnalStatetoDb(String index, String state) 
	{
	 	try
	 	{
	 		stmt = conn.connect().createStatement();
	 		
	 		String sql = "INSERT INTO j_wang_device_data (signal_index, signal_state)" + " VALUES ('"+index +"', '"+state+"' )";
		 	stmt.executeUpdate(sql);
		 	conn.connect().close();
	 	}
		catch (SQLException se) 
	  	{ se.printStackTrace();  }
	}	
	
	// Clear method
	public void ClearDb() 
	{
	 	 try 
		 {
	  		stmt = conn.connect().createStatement();
	  		String sql = null;
			  
	  		sql = "DELETE FROM j_wang_device_data";
	  		stmt.executeUpdate(sql);
	  		sql = "DELETE FROM j_wang_device_user";
	  		stmt.executeUpdate(sql);
	  		conn.connect().close();
		}
		catch (SQLException se)
		{ se.printStackTrace();  }
	}// INSERT INTO METHOD		
}
	
